$(function(){

})
var aCity={11:"北京",12:"天津",13:"河北",14:"山西",15:"内蒙古",21:"辽宁",22:"吉林",23:"黑龙江",31:"上海",32:"江苏",33:"浙江",34:"安徽",35:"福建",36:"江西",37:"山东",41:"河南",42:"湖北",43:"湖南",44:"广东",45:"广西",46:"海南",50:"重庆",51:"四川",52:"贵州",53:"云南",54:"西藏",61:"陕西",62:"甘肃",63:"青海",64:"宁夏",65:"新疆",71:"台湾",81:"香港",82:"澳门",91:"国外"} 



 /**
 * 手机号码校验
 */
function isPoneAvailable(str) {  
    var myreg=/^[1][3,4,5,7,8][0-9]{9}$/;  
    if (!myreg.test(str)) {  
        return false;  
    } else {  
        return true;  
    }  
}

/**
 * 内部账户 空指针设置  为空返回【未设置】
 */
function isNullNotSet(value){
	if(null !=value && '' != value){
		return value;
	}else{
		return '【未设置】';
	}
}

var phoneDisplay = function (m) {
    if (m.length >= 11) {
        return m.substring(0, 3) + "****" + m.substring(8, 11);
    }
    return m;
}


//格式化千位符
var thousandBitSeparator = function (num) {
	var newNum = parseInt(num);
	var num = (num || 0).toString(), result = '';
	while (num.length > 3) {
	    result = ',' + num.slice(-3) + result;
	    num = num.slice(0, num.length - 3);
	}
	if (num) { result = num + result; }
	return result + ".00";
}

// 过滤返回值的null
var filtration_String_return_null = function (s) {
    if (s) {
        return s;
    }
    return "";
};

//小数点两位
var chkdecimalt = function (val) {
    return /^[0-9]+([.]\d{1,2})?$/.test(val);
};

//取数值小数点两位 不足补0
var changeTwoDecimal = function (x) {
    var f_x = x;
    if (isNaN(f_x) || f_x == null) {
        return "0.00";
    }
    var s_x = f_x.toString();
    var pos_decimal = s_x.indexOf(".");
    if (pos_decimal < 0) {
        pos_decimal = s_x.length;
        s_x += ".";
    }
    if (s_x.length - pos_decimal > 3) {
        s_x = s_x.substring(0, pos_decimal + 3);
    } else {
        while (s_x.length <= pos_decimal + 2) {
            s_x += 0;
        }
    }
    return s_x;
};

//扩展日期格式化
Date.prototype.format = function (format) {
    var o = {
        "M+": this.getMonth() + 1, // month
        "d+": this.getDate(), // day
        "h+": this.getHours(), // hour
        "m+": this.getMinutes(), // minute
        "s+": this.getSeconds(), // second
        "q+": Math.floor((this.getMonth() + 3) / 3), // quarter
        "S": this.getMilliseconds()
        // millisecond
    };
    if (/(y+)/.test(format))
        format = format.replace(RegExp.$1, (this.getFullYear() + "")
            .substr(4 - RegExp.$1.length));
    for (var k in o)
        if (new RegExp("(" + k + ")").test(format))
            format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k]
                : ("00" + o[k]).substr(("" + o[k]).length));
    return format;
};

/* 
 *  方法:Array.remove(dx) 
 *  功能:根据元素值删除数组元素. 
 *  参数:元素值 
 *  返回:在原数组上修改数组 
 *  作者：pxp 
 */  
Array.prototype.indexOf = function (val) {  
    for (var i = 0; i < this.length; i++) {  
        if (this[i] == val) {  
            return i;  
        }  
    }
	
	/**
	 * 内部账户 空指针设置  为空返回【未设置】
	 */
	function isNullNotSet(value){
		if(null !=value && '' != value){
			return value;
		}else{
			return '【未设置】';
		}
	}
    return -1;  
};  

Array.prototype.indexOfName = function (name) {  
    for (var i = 0; i < this.length; i++) {  
        if (this[i].name == name) {  
            return -1;  
        }  
    }  
    return 1;  
}; 

Array.prototype.remove = function (val) {  
    var index = this.indexOf(val);  
    if (index > -1) {  
        this.splice(index, 1);  
    }  
};



/**
 * 返回周期
 * @param num
 * @param type
 */
function  periodToString(num,type){
	if(type=='week'){
		  return num+'周';
		}else if(type=='month'){
		  return num+'个月';
		}else if(type == 'year'){
		  return num+'年';
		}else{
		  return num+'天';
		}
}

/**
 * obj 转json
 * @param data
 * @returns
 */
var toJson =  function(data) {
    var json = data
    try {
        if (typeof json === 'object') json = json.toString()
        if (!json.trim().match("^\{(.+:.+,*){1,}\}$")) return data;
        else return JSON.parse(data);
    } catch (e) {
        return data;
    }
}

var sendMsgModify = function(mobile,apiType){
	$.ajax({
		url:g_requestContextPath + "/user/sendMsgModify",
		type:"post",
		data:{
			"mobile": mobile,
			"apiType" : apiType
		},
		success:function(data){
			//console.log('返回内容：\n'+ JSON.stringify(data));
			var json =toJson(data);
			if(json.result != 'success'){
				layer.msg(json.result);
				return;
			}else{
				
			}
		}
	});
}

/**
 * 身份证号码校验
 * @param sId
 * @returns {String}
 */
function isCardID(sId){
	 var iSum=0 ;
	 var info="" ;
	 if(!/^\d{17}(\d|x)$/i.test(sId)) return "你输入的身份证长度或格式错误";
	 sId=sId.replace(/x$/i,"a");
	 if(aCity[parseInt(sId.substr(0,2))]==null) return "你的身份证地区非法";
	 sBirthday=sId.substr(6,4)+"-"+Number(sId.substr(10,2))+"-"+Number(sId.substr(12,2));
	 var d=new Date(sBirthday.replace(/-/g,"/")) ;
	 if(sBirthday!=(d.getFullYear()+"-"+ (d.getMonth()+1) + "-" + d.getDate()))return "身份证上的出生日期非法";
	 for(var i = 17;i>=0;i --) iSum += (Math.pow(2,i) % 11) * parseInt(sId.charAt(17 - i),11) ;
	 if(iSum%11!=1) return "你输入的身份证号非法";
	 //aCity[parseInt(sId.substr(0,2))]+","+sBirthday+","+(sId.substr(16,1)%2?"男":"女");//此次还可以判断出输入的身份证号的人性别
	 return 'true';
}

/**
 * 银行卡号 校验规则
 * @param t_bankno
 * @returns {Boolean}
 */
function CheckBankNo(t_bankno) {
  　　var bankno = $.trim(t_bankno);
  　　if(bankno == "") {
    　	layer.msg("请填写银行卡号");
     	return false;
   	 }
   if(bankno.length < 16 || bankno.length > 19) {
	   layer.msg("银行卡号长度必须在16到19之间");
       return false;
   }
   var num = /^\d*$/; //全数字
   if(!num.exec(bankno)) {
	   layer.msg("银行卡号必须全为数字");
     return false;
   }
   //开头6位
   var strBin = "10,18,30,35,37,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,58,60,62,65,68,69,84,87,88,94,95,98,99";
   if(strBin.indexOf(bankno.substring(0, 2)) == -1) {
	   layer.msg("银行卡号开头6位不符合规范");
     return false;
   }
   return true;
   }

//判断 是否为正确金额
function isMoney(s) {   
    var regu = /^(([1-9][0-9]*)|(([0]\.\d{1,2}|[1-9][0-9]*\.\d{1,2})))$/;   
    var re = new RegExp(regu);   
    if (re.test(s)) {   
        return true;   
    } else {   
        return false;   
    }   
}  

/**
 * 后台 金额格式化
 * @param s
 * @param n
 * @returns {String}
 */
function fmoney(s) {
	var n = 2;
	n = n > 0 && n <= 20 ? n : 2; 
	s = parseFloat((s + "").replace(/[^\d\.-]/g, "")).toFixed(n) + ""; 
	var l = s.split(".")[0].split("").reverse(), r = s.split(".")[1]; 
	t = ""; 
	for (i = 0; i < l.length; i++) { 
	t += l[i] + ((i + 1) % 3 == 0 && (i + 1) != l.length ? "," : ""); 
	} 
	return t.split("").reverse().join("") + "." + r; 
}

/** 
 * 设置select控件选中 
 * @param selectId select的id值 
 * @param checkValue 选中option的值 
 * @author 标哥 
*/  
function set_select_checked(selectId, checkValue){  
    var select = document.getElementById(selectId);  

    for (var i = 0; i < select.options.length; i++){  
        if (select.options[i].value == checkValue){  
            select.options[i].selected = true;  
            break;  
        }  
    }  
}
/**
 * 登录加密
 * @param password
 * @returns
 */
function encryptionPwd(password){
	var encryption = "###" + md5(md5("8txuGjgpHti6TANE6D" + password));
	return encryption;
}
/**
 * 加密交易密码
 * @param payPassword
 * @returns
 */
function encryptionPayPwd(payPassword){
	return md5(md5(payPassword));
}